package com.lvmama.rhino.common.utils.spark

import org.apache.spark.{SparkConf, SparkContext}

/**
  * Created by yuanxiaofeng on 2016/6/23.
  */
trait SparkApplication {
  var appName: String

  var sparkConfig: Map[String, String]

  def withSparkContext(f: SparkContext => Unit): Unit = {
    val conf = new SparkConf()

    sparkConfig.foreach{case (k, v) => conf.setIfMissing(k, v)}

    val sc = new SparkContext(conf)

    f(sc)
  }
}
